package com.ftg.learn.day12;

/**
 * 学习一下递归
 *
 * @author 布衣
 */
public class LearnRecursion {

    //    1 -10
    public int sum(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += i;
        }
        return sum;
    }

    public int f(int z) {
        //终止条件
        if (z == 1) {
            return 1;
        }
        //要找出方法设计当中的通用模块
        return z + f(z - 1);
    }


    public static void main(String[] args) {
        LearnRecursion learnRecursion = new LearnRecursion();
        long l1 = System.currentTimeMillis();
        System.out.println(learnRecursion.f(10000));
        long l2 = System.currentTimeMillis();
        System.out.println(l2 - l1);

        long l3 = System.currentTimeMillis();
        System.out.println(learnRecursion.sum(10000));
        long l4 = System.currentTimeMillis();
        System.out.println(l4 - l3);

//        System.out.println("=================================>");

    }
}
